﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.Exceptions.DataBase;
using System.Data;
namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeReciptDetailsByReciptIdDataAction : BestLifeDataAction<List<Recipt_Detail>>
    {

        private string GvReciptId;
        public BestLifeReciptDetailsByReciptIdDataAction(string PReciptId)
        {
            GvReciptId = PReciptId;
        }

        public override List<Recipt_Detail> Body(SqlConnection PConn)
        {
            try
            {
                List<Recipt_Detail> LvList = new List<Recipt_Detail>();


                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.GetReciptDetailsbyReceiptID";
                LvCommand.Parameters.Add(new SqlParameter("@ReceiptID", GvReciptId));


                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {
                    Recipt_Detail LvRecipt = new Recipt_Detail();
                    LvRecipt.R_ID = LvReader.GetValue(0).ToString();
                    LvRecipt.Dis_ID = LvReader.GetValue(1).ToString();
                    LvRecipt.Branch_Id = LvReader.GetValue(2).ToString();
                    LvRecipt.Date_Create = DateTime.Parse(LvReader.GetValue(3).ToString());
                    LvRecipt.Pay_Method = LvReader.GetValue(4).ToString();
                    LvRecipt.Term_Id = LvReader.GetValue(5).ToString();
                    LvRecipt.Price = Decimal.Parse(LvReader.GetValue(6).ToString());


                    LvList.Add(LvRecipt);
                }


                return LvList;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
